package com.hongyuan.venue.ui.home.view_mode;

import android.app.Application;
import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableField;
import androidx.databinding.ObservableList;
import com.google.gson.reflect.TypeToken;
import com.hongyuan.venue.R;
import com.hongyuan.venue.base.CustomViewModel;
import com.hongyuan.venue.data.MyRepository;
import com.hongyuan.venue.ui.home.beans.Venue;
import com.hongyuan.venue.utils.GsonUtil;
import java.util.List;
import me.tatarka.bindingcollectionadapter2.BR;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

public class HomeScheduledViewModel extends CustomViewModel<MyRepository> {

    //需要传递过去的id
    public ObservableField<String> gcId = new ObservableField<>();

    //给RecyclerView添加ObservableList
    public ObservableList<HomeScheduledItemViewModel> observableList = new ObservableArrayList<>();

    //给RecyclerView添加ItemBinding
    public ItemBinding<HomeScheduledItemViewModel> itemBinding = ItemBinding.of(BR.viewModel, R.layout.item_home_scheduled);

    public HomeScheduledViewModel(@NonNull Application application, MyRepository repository) {
        super(application, repository);
    }

    /*
    * 设置数据
    * */
    public void setData(String datas){
        try {
            List<Venue.GcListBean.TypeBean> mList = GsonUtil.getGson().fromJson(datas, new TypeToken<List<Venue.GcListBean.TypeBean>>(){}.getType());

            for(Venue.GcListBean.TypeBean bean : mList){
                HomeScheduledItemViewModel itemViewModel = new HomeScheduledItemViewModel(this,bean);
                observableList.add(itemViewModel);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
